package com.dwxt.sport.business.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.sport.business.entity.FitnessSurvey;
import com.dwxt.sport.business.entity.FitnessSurveyEquipment;
import com.dwxt.sport.business.service.FitnessSurveyService;
import com.dwxt.sport.business.vo.fitnessSurvey.InsertOrUpdateFitnessSurveyEquipmentVo;
import com.dwxt.sport.business.vo.fitnessSurvey.InsertOrUpdateFitnessSurveyVo;
import com.dwxt.sport.business.vo.fitnessSurvey.SelectFitnessSurveyVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 体质监测中心 Controller
 *
 * @author Kuang.JiaZhuo
 * @date 2020-07-28 15:20
 */
@RestController
@RequestMapping("/fitnessSurvey")
@Api(tags={"体质监测中心相关接口"})
public class FitnessSurveyController {

    @Resource
    FitnessSurveyService fitnessSurveyService;

    @ApiOperation(value = "新增室体质监测中心", notes = "新增室体质监测中心", response = Integer.class)
    @PostMapping("/back/insertFitnessSurvey")
    public BaseResult insertFitnessSurvey(InsertOrUpdateFitnessSurveyVo insertVo){
        int result = this.fitnessSurveyService.insertFitnessSurvey(insertVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "更新体质监测中心", notes = "更新体质监测中心", response = Integer.class)
    @PostMapping("/back/updateFitnessSurvey")
    public BaseResult updateFitnessSurvey(InsertOrUpdateFitnessSurveyVo updateVo){
        int result = this.fitnessSurveyService.updateFitnessSurvey(updateVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "获取体质监测中心列表", notes = "按条件查询体质监测中心列表(带分页)", response = FitnessSurvey.class)
    @PostMapping("/back/getFitnessSurveyByPage")
    public BaseResult getFitnessSurveyByPage(SelectFitnessSurveyVo selectVo){
        PageInfo<FitnessSurvey> pageInfo = this.fitnessSurveyService.getFitnessSurveyByPage(selectVo);
        return BaseResult.ok(pageInfo);
    }

    @ApiOperation(value = "删除体质监测中心", notes = "根据ids批量删除体质监测中心", response= Integer.class)
    @PostMapping(value = "/back/deleteFitnessSurveyByIds")
    public BaseResult deleteFitnessSurveyByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.fitnessSurveyService.deleteFitnessSurveyByIds(ids);
        return BaseResult.ok(result);
    }

    /******************************************************************  关联设备  ******************************************************************************/

    @ApiOperation(value = "新增体质监测中心的设备关联", notes = "新增体质监测中心的设备关联", response = Integer.class)
    @PostMapping("/back/insertFitnessSurveyEquipment")
    public BaseResult insertFitnessSurveyEquipment(InsertOrUpdateFitnessSurveyEquipmentVo insertVo){
        int result = this.fitnessSurveyService.insertFitnessSurveyEquipment(insertVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "更新体质监测中心的设备关联", notes = "更新体质监测中心的关联设备信息", response = Integer.class)
    @PostMapping("/back/updateFitnessSurveyEquipment")
    public BaseResult updateFitnessSurveyEquipment(InsertOrUpdateFitnessSurveyEquipmentVo updateVo){
        int result = this.fitnessSurveyService.updateFitnessSurveyEquipment(updateVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "查询体质监测中心的设备列表", notes = "根据体质监测中心的id查询关联设备的列表(带分页)", response= FitnessSurveyEquipment.class)
    @PostMapping(value = "/back/getFitnessSurveyEquipmentByPage")
    public BaseResult getFitnessSurveyEquipmentByPage(@ApiParam(value = "体质监测中心id", required = true) @RequestParam String id,
                                                       @ApiParam(value = "起始页", required = true) @RequestParam Integer pageNum,
                                                       @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize){
        String fitnessSurveyId = id;
        PageInfo<FitnessSurveyEquipment> pageInfo = this.fitnessSurveyService.getFitnessSurveyEquipmentByPage(pageNum,pageSize,fitnessSurveyId);
        return BaseResult.ok(pageInfo);
    }

    @ApiOperation(value = "删除体质监测中心关联设备", notes = "根据ids批量删除体质监测中心关联的设备", response= Integer.class)
    @PostMapping(value = "/back/deleteFitnessSurveyEquipmentByIds")
    public BaseResult deleteFitnessSurveyEquipmentByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.fitnessSurveyService.deleteFitnessSurveyEquipmentByIds(ids);
        return BaseResult.ok(result);
    }


}
